package henu.graduation_design.onlineshop;

import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.Window;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TabHost;

@SuppressWarnings("deprecation")
public class TabActivity extends android.app.TabActivity implements
		OnCheckedChangeListener {

	private RadioGroup group;
	private TabHost tabHost;
	private Intent iHome;
	private Intent iStar;
	private Intent iProfile;
	private Intent iSetting;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_tab);
		tabHost = getTabHost();

		iHome = new Intent(this, HomeActivity.class);
		tabHost.addTab(tabHost.newTabSpec("iHome").setIndicator("iHome")
				.setContent(iHome));

		iStar = new Intent(this, ProductStarActivity.class);
		tabHost.addTab(tabHost.newTabSpec("iStar").setIndicator("iStar")
				.setContent(iStar));
		
		iProfile = new Intent(this,ProfileActivity.class);
		tabHost.addTab(tabHost.newTabSpec("iProfile").setIndicator("iProfile")
				.setContent(iProfile));
		
		iSetting=new Intent(this,SettingsActivity.class);
		tabHost.addTab(tabHost.newTabSpec("iSetting").setIndicator("iSetting")
				.setContent(iSetting));

		group = (RadioGroup) findViewById(R.id.main_tab);
		group.setOnCheckedChangeListener(this);
	}

	@Override
	public void onCheckedChanged(RadioGroup group, int checkedId) {
		// TODO Auto-generated method stub
		switch (checkedId) {
		case R.id.tab_home:
			this.tabHost.setCurrentTabByTag("iHome");
			break;
		case R.id.tab_star:
			this.tabHost.setCurrentTabByTag("iStar");
			break;
		case R.id.tab_profile:
			this.tabHost.setCurrentTabByTag("iProfile");
			break;
		case R.id.tab_setting:
			this.tabHost.setCurrentTabByTag("iSetting");
			break;
		default:
			break;
		}
	}

	@Override
	protected void onDestroy() {
		SharedPreferences sp = getSharedPreferences("SP", MODE_PRIVATE);
		Editor editor = sp.edit();
		editor.putBoolean("IsLogin", false);
		editor.commit();
		super.onDestroy();
		System.exit(0);
	}

}
